/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		   */
/*																   */
/*	NAME	  = t__sqlserver_bigint_add.c						   */
/*	NOTE	  = 												   */
/*	DATE	  = 2014/11/25 by geyh								   */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <informix/config.h>
#include <informix/informix_core.h>

extern int informix_parse_rbwork(Conntrack *p_st_conn, L7session_informix_private *p_st_private);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = FR_SUCC;
    L7session_informix_private *p_st_private = (L7session_informix_private *) frmalloc(sizeof(L7session_informix_private));
    memset(p_st_private, 0x00, sizeof(L7session_informix_private));
    L7_fragment_informix *p_st_fragment = (L7_fragment_informix *) frmalloc(sizeof(L7_fragment_informix));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_informix));
    L7_req_informix *p_st_req = (L7_req_informix *) frmalloc(sizeof(L7_req_informix));
    memset(p_st_req, 0x0, sizeof(L7_req_informix));
    p_st_private->p_st_fragment = p_st_fragment;
    p_st_private->p_st_req = p_st_req;
    p_st_private->p_st_fragment = p_st_fragment;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x00", 1);
    p_st_fragment->p_st_data = p_st_data;

    i_ret = informix_parse_rbwork(NULL, p_st_private);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    informix_session_destroy(p_st_private);
    return;
}

static void __case2(void)
{
    int i_ret = FR_SUCC;
    L7session_informix_private *p_st_private = (L7session_informix_private *) frmalloc(sizeof(L7session_informix_private));
    memset(p_st_private, 0x00, sizeof(L7session_informix_private));
    L7_fragment_informix *p_st_fragment = (L7_fragment_informix *) frmalloc(sizeof(L7_fragment_informix));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_informix));
    L7_req_informix *p_st_req = (L7_req_informix *) frmalloc(sizeof(L7_req_informix));
    memset(p_st_req, 0x0, sizeof(L7_req_informix));
    p_st_private->p_st_fragment = p_st_fragment;
    p_st_private->p_st_req = p_st_req;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x00\x06", 2);
    p_st_fragment->p_st_data = p_st_data;

    i_ret = informix_parse_rbwork(NULL, p_st_private);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    informix_session_destroy(p_st_private);
    return;
}

int add_suite_informix_parse_rbwork(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" informix_parse_rbwork()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
